$(function (){
  /*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

// Wait for the deviceready event before using any of Cordova's device APIs.
// See https://cordova.apache.org/docs/en/latest/cordova/events/events.html#deviceready
  document.addEventListener("deviceready", onDeviceReady, false);

  function onDeviceReady() {
    // Cordova is now initialized. Have fun!

    console.log("Running cordova-" + cordova.platformId + "@" + cordova.version);
    document.getElementById("deviceready").classList.add("ready");
  }
// 初始化 Vue 实例
  const app = Vue.createApp({
    data() {
      return {
        activeName: 'advertisingList',
        searchName: '',
        list: [],
        loading: false,
        finished: true,
        refreshing: false,
        searchParams: {
          pageNum: 1,
          pageSize: 10,
        },
        tabData: {
          advertising: {
            id: 7,
            name: '广告'
          },
          plaque: {
            id: 8,
            name: '牌匾'
          },
          front: {
            id: 9,
            name: '临街门面'
          },
          market: {
            id: 10,
            name: '便民市场'
          },
        },
        //       completeFlag: "1", // 处置情况(0 注销 1 处置完成 2 退回 3 归档 4 未处理)
        statusData: {
          0: {
            txt: '注销',
            status: 'danger',
          },
          1: {
            txt: '处置完成',
            status: 'success',
          },
          2: {
            txt: '退回',
            status: 'warning',
          },
          3: {
            txt: '归档',
            status: 'primary',
          },
          4: {
            txt: '未处理',
            status: 'default',
          },
        },
      };
    },
    mount() {},
    methods: {
      onClickButton(){
        this.getList()
      },
      changeTab(){
        this.searchName = ''
        this.getList()
      },
      toDetail(item){
        location.href = `./${this.activeName}Detail.html?id=${item.caseId}&activeName=${this.activeName}`;
      },
      onClickLeft() {
        history.back();
      },
      clickRight(){
        location.href = `./add${this.activeName.charAt(0).toUpperCase()}${this.activeName.slice(1)}.html?activeName=${this.activeName}&id=${this.tabData[this.activeName].id}&name=${this.tabData[this.activeName].name}`;
      },
      getList(){
        const vm = this;
        $.ajax({
          async: true,
          cache: false,
          type: "get",
          url: globalApi.hosts + listApi[vm.activeName].list,
          data: {
            caseTitle: vm.searchName,
          },
          success: function (res) {
            if(res.code == 200){
              vm.searchParams.pageNum++;
              vm.list = res.data;
              vm.total = res.total;
              vm.loading = false;
              vm.finished = true;
              vm.refreshing = false;
              // if (vm.list.length && vm.list.length >= vm.total) {
              //   vm.finished = true;
              // }
            }
          }
        });
      },
      onLoad() {
        this.getList()
        // setTimeout(() => {
        //   if (this.refreshing) {
        //     this.list = [];
        //     this.refreshing = false;
        //   }
        //
        //   for (let i = 0; i < 10; i++) {
        //     this.list.push({
        //       createBy: "1", // 创建者
        //       createTime: "2025-01-22 20:06:12", // 创建时间("yyyy-MM-dd")
        //       remark: null, // 案件主键
        //       caseId: 1, // 案件主键
        //       caseNumber: "1", // 案件编号
        //       caseTitle: "1", // 案件标题
        //       relevancyId: "1", // 关联主键
        //       typeId: "1", // 类型主键
        //       typeName: "1", // 类型名称
        //       areaId: 1, // 区编码
        //       areaName: "1", // 区名称
        //       streetId: 1, // 街道编码
        //       streetName: "1", // 街道名称
        //       location: "1", // 位置描述
        //       eventType: "1", // 事件类型
        //       eventInfo: "1", // 事件描述
        //       processLimited: "1", // 处理时限
        //       caseRemark: "1", // 案件备注
        //       completeFlag: "1", // 处置情况(0 注销 1 处置完成 2 退回 3 归档 4 未处理)
        //       completeInfo: "1", // 处置说明
        //       completeBy: "1", // 完成人主键
        //       completeTime: "2025-01-22", // 完成时间("yyyy-MM-dd")
        //     });
        //   }
        //   this.loading = false;
        //
        //   if (this.list.length >= 40) {
        //     this.finished = true;
        //   }
        // }, 1000);
      },
      onRefresh() {
        // 清空列表数据
        this.finished = false;

        // 重新加载数据
        // 将 loading 设置为 true，表示处于加载状态
        this.loading = true;
        this.onLoad();
      },
    },
  });

  app.use(vant);
  app.mount("#app");

})